package com.jgraph.editor.persistence;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;

/**
 * This interface defines the contract for persistence managers which
 * are responsible for reading and writing files. Each persistence manager
 * supports one or more file types and handles (reads/writes) specific type
 * of objects. 
 *
 * @param T The type of objects handled by this persistence manager.
 *
 * @author svetoslavganov@mail.utexas.edu
 *
 */
public interface JGraphPersistenceManager<T> {

	/**
	 * Reads a serialized object given its {@link URI}.
	 *
	 * @param uri The file {@link URI}.
	 * @return A read instance.
	 */
	public abstract T readObject(String uri)
	        throws MalformedURLException, IOException;

	/**
	 * Writes an object to a given {@link URI}.
	 *
	 * @param file The object to write.
	 * @param uri The {@link URI} to write the object to.
	 */
	public abstract void writeObject(T object, String uri)
	        throws MalformedURLException, IOException;

	/**
	 * Create an input stream for a given {@link URI}.
	 *
	 * @param uri The URI to return the input stream for.
	 * @return The input stream.
	 */
	public InputStream getInputStream(String uri)
	        throws MalformedURLException, FileNotFoundException, IOException;

	/**
	 * Creates an output stream for the specified URI.
	 *
	 * @param uri The URI to return the output stream for.
	 * @return The output stream.
	 */
	public OutputStream getOutputStream(String uri) throws IOException;
}
